package com.fejal.bean;

import java.io.Serializable;
import java.util.Collection;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.JoinTable;
import javax.persistence.ManyToMany;
import javax.persistence.ManyToOne;
import javax.persistence.OneToOne;
import org.hibernate.annotations.Cascade;
import org.hibernate.annotations.CascadeType;
import org.hibernate.annotations.Fetch;
import org.hibernate.annotations.FetchMode;

@Entity
public class GradeDisciplina implements Serializable{

	private static final long serialVersionUID = -4614795685471791371L;

	@Id
	@GeneratedValue (strategy = GenerationType.AUTO)
	private int codigoGradeDisciplina;
	
	@OneToOne
	@JoinColumn(name = "codigoDisciplina")	
	private Disciplina disciplina;
	
	private int periodo;
	
	@ManyToOne(fetch = FetchType.EAGER)
	@JoinColumn(name="codigoGradeCurricular",
	insertable=true, updatable=true)
	@Fetch(FetchMode.JOIN)
	@Cascade(CascadeType.SAVE_UPDATE)
    private GradeCurricular gradeCurricular ;	
	
	@ManyToMany(fetch=FetchType.LAZY)
	@JoinTable(name="GradePreRequisito",
	joinColumns=@JoinColumn(name="codigoGradeDisciplina"),
	inverseJoinColumns=@JoinColumn(name="codigoGradeDisciplinaPreRequisito"))
	private Collection<GradeDisciplina> preRequisitos;	
	

	public GradeDisciplina(){
		
	}

	public int getCodigoGradeDisciplina() {
		return codigoGradeDisciplina;
	}

	public void setCodigoGradeDisciplina(int codGradeDisciplina) {
		this.codigoGradeDisciplina = codGradeDisciplina;
	}

	public Disciplina getDisciplina() {
		return disciplina;
	}

	public void setDisciplina(Disciplina disciplina) {
		this.disciplina = disciplina;
	}

	public int getPeriodo() {
		return periodo;
	}

	public void setPeriodo(int periodo) {
		this.periodo = periodo;
	}

	public Collection<GradeDisciplina> getPreRequisitos() {
		return preRequisitos;
	}

	public void setPreRequisitos(Collection<GradeDisciplina> preRequisitos) {
		this.preRequisitos = preRequisitos;
	}

	public GradeCurricular getGradeCurricular() {
		return gradeCurricular;
	}

	public void setGradeCurricular(GradeCurricular gradeCurricular) {
		this.gradeCurricular = gradeCurricular;
	}

	@Override
	public int hashCode() {
		final int prime = 31;
		int result = 1;
		result = prime * result + codigoGradeDisciplina;
		return result;
	}

	@Override
	public boolean equals(Object obj) {
		if (this == obj)
			return true;
		if (obj == null)
			return false;
		if (getClass() != obj.getClass())
			return false;
		GradeDisciplina other = (GradeDisciplina) obj;
		if (codigoGradeDisciplina != other.codigoGradeDisciplina)
			return false;
		return true;
	}
}
